package com.fanfan.SmartPensionSystembackend.mapper;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fanfan.SmartPensionSystembackend.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description userMapper
 * @Author Guangdi Chen
 * @Date 2025-03-05
 */
@Mapper
@TableName(value = "sysuser", autoResultMap = true) // 明确指定表名
public interface UserMapper extends BaseMapper<User> {

    //注册用户
    @Insert("INSERT INTO sysuser (userId ,username, password, realName, phone, userType) VALUES (#{userId},#{username}, #{password}, #{realName}, #{phone}, #{userType})")
    int insert(User user);

    // 根据用户名查询用户信息
    @Select("SELECT * FROM sysuser WHERE username = #{username}")
    User selectOneByUsername(String username);

    // 更新用户密码
    @Update("UPDATE sysuser SET password = #{password} WHERE username = #{username}")
    int updateByUsername(User user);

    // 获取所有用户信息
    @Select("SELECT * FROM sysuser")
    List<User> selectAllUsers();

    //更新用户信息
    @Update("UPDATE sysuser SET username = #{username}, password = #{password}, realName = #{realName}, phone = #{phone}, userType = #{userType} WHERE userId = #{userId}")
    int updateById(User user);

    //删除用户
    @Delete("DELETE FROM sysuser WHERE userId = #{userId}")
    int deleteById(String userId);
}